package besteAukera;

/**
 * 
 */
import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class And extends AteLogikoak {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea ;
	private Vector<Hanka> sarreraBektorea;
	private Hanka s1, s2, i1;

	/**
	 * Behar dituen parametroak pasata And logikoa eta And, Or, Nor eta Nand
	 * fisikoak sortzeko eraikitzailea.
	 * 
	 * @param x1
	 *            :And logikoaren irudiko elipsearen ezker iskineko x
	 *            koordenatua.
	 * @param y1
	 *            :And logikoaren irudiko elipsearen goiko iskineko y
	 *            koordenatua.
	 * @param hankaKop
	 *            :And-aren hanka kopurua.
	 * @param sarKop
	 *            :And-aren sarrera kopurua.
	 * @param motaFis
	 *             :Hankak marrazterakoan zein And fisiko den jakiteko.
	 * @param kolorea
	 */

	public And(int x1, int y1, int hankaKop,int sarKop, String motaFis, Color kolorea) {
		super(x1, y1, hankaKop, sarKop,motaFis, kolorea);

		// TODO Auto-generated constructor stub
		if (motaFisikoa.compareTo("and") == 0) {
			s1 = new Hanka(x + 15, y + 50/4, "positiboa", "s", 0, this,
					"h", "ez",true);
			s2 = new Hanka(x + 15, y + 50 - 50/4, "positiboa", "s", 1,
					this, "h", "ez",true);
			i1 = new Hanka(x +90, y + 25, "positiboa", "i", 2,
					this, "h", "ez",true);
		} else if (motaFisikoa.compareTo("nor") == 0) {
			s1 = new Hanka(x + 15, y + 12, "negatiboa", "s", 0, this, "h", "ez",true);

			s2 = new Hanka(x + 15, y + 36, "negatiboa", "s", 1, this, "h", "ez",true);

			i1 = new Hanka(x + 90, y + 24, "positiboa", "i", 2, this,
					"h", "ez",true);
		} else if (motaFisikoa.compareTo("nand") == 0) {
			s1 = new Hanka(x + 15, y + 12, "positiboa", "s", 0, this, "h", "ez",true);

			s2 = new Hanka(x + 15, y + 36, "positiboa", "s", 1, this, "h", "ez",true);

			i1 = new Hanka(x + 90, y + 24, "negatiboa", "i", 2, this, "h",
					"ez",true);
		}

		else if (motaFisikoa.compareTo("or") == 0) {
			s1 = new Hanka(x + 15, y + 12, "negatiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x + 15, y + 36, "negatiboa", "s", 1, this, "h", "ez",true);
			i1 = new Hanka(x + 90, y + 24, "negatiboa", "i", 2, this, "h",
					"ez",true);
		}
	
		lotList[0] = s1;
		lotList[1] = s2;
		lotList[2] = i1;

	}

	/**
	 * And txipa marrazten du.
	 */

	public void marraztu(Graphics g) {
	
		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		g.drawArc(x, y, 70, 50, 270, 180);
		g.drawLine(x + 35, y, x + 35, y + 50);
	
		s1.marraztu(g);
		s2.marraztu(g);
		i1.marraztu(g);
		}
	
/**
 * And txiparen irteerako hankari and eragiketa logikoaren balioa
 * emango dio:
 * 
 * 1&1=1
 * 1&0=0
 * 0&1=0
 * 0&0=0
 * 
 * @param And-aren sarrerako biten balioa
 */
	@Override
	protected void funtzioLogikoa(Integer... values) {
		
		lotList[2].getIrteera().setBalioa(
				s1.getSarrera().getBalioa() & s2.getSarrera().getBalioa());
		
	}
/**
 * And txipeko hankak hankaBektorea Vector-en sartzen du.
 * 
 * @return And txiparen hanken bektorea
 */
	public Vector<Hanka> getHankak() {

		hankaBektorea = new Vector<Hanka>();
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(i1);
	
		return hankaBektorea;
	}
	/**
	 * And txipeko sarrerako hankak hankaBektorea Vector-en 
	 * sartzen du.
	 * 
	 * @return And txiparen sarrera hanken bektorea
	 */
	public Vector<Hanka> getSarreraHankak() {
		sarreraBektorea = new Vector<Hanka>();
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		return sarreraBektorea;
	}

}